package 笔试;

/**
 * @Date 2024/11/3 20:38
 * @description: 建信融通笔试
 * .
 * @Author LittleNight
 */
public class jianxinrongtong {

    // 翻转一个字符串, 并统计字符出现的次数
    public static void main(String[] args) {
        String str = "hello world";
        StringBuilder sb = new StringBuilder(str);
        String reverseStr = sb.reverse().toString();
        System.out.println(reverseStr);

        //统计字符出现的次数
        int[] count = new int[26];
        for (int i = 0; i < reverseStr.length(); i++) {
            char ch = reverseStr.charAt(i);
            if(ch >= 'a' && ch <= 'z') count[ch - 'a']++;
        }
        for (int i = 0; i < count.length; i++) {
            if (count[i] != 0) {
                char ch = (char) ('a' + i);
                System.out.println(ch + ":" + count[i]);
            }
        }
    }
    // 找到和最大的连续子数组的和
    public static int maxSubArray(int[] nums) {
        int maxSum = nums[0];
        int curSum = nums[0];
        for (int i = 1; i < nums.length; i++) {
            curSum = Math.max(nums[i], curSum + nums[i]);
            maxSum = Math.max(maxSum, curSum);
        }
        return maxSum;
    }

}
